package com.chenhongjian.webapp.config;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * Created by a on 2018/3/26.
 */
@Configuration
public class WebAppConfig implements WebMvcConfigurer {


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String whiteList[] = new String[]{"/api/test",
                "/api/index",
                "/api/saveUserByNameAndPhone",
                "/api/login",
                "/api/phoneLogin",
                "/index",
                "/api/smssend",
                "/nonedata",
               "/api/upload",
                "/api/upload_content",
        "/api/list",
        "/api/vote"};
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/api/**").excludePathPatterns(whiteList);
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/templates/**").addResourceLocations("classpath:/templates/");
    }
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
    public static String LOGIN_USER = "login_user";
}
